
package com.game.model;

import com.game.global.CrashType;
import com.game.interfaces.CollisionAble;
import com.game.interfaces.Draw;
import com.game.interfaces.LifeCycle;
import com.game.util.ImageUtil;
import com.game.util.PropertiesUtil;

import java.awt.*;
import java.util.concurrent.atomic.AtomicBoolean;

// 老家
public class Home extends Module implements Draw, CollisionAble, LifeCycle {

    private AtomicBoolean alive = new AtomicBoolean(false);

    public Home() {
        SIZE_X = PropertiesUtil.loadInt("home.width");
        SIZE_Y = PropertiesUtil.loadInt("home.length");
    }

    @Override
    public Rectangle getRec() {
        return new Rectangle(localX, localY, SIZE_X, SIZE_Y);
    }

    @Override
    public int getCollisionType() {
        return CrashType.HOME;
    }

    @Override
    public int getRight() {
        return localX + SIZE_X;
    }

    @Override
    public int getBottom() {
        return localY + SIZE_Y;
    }

    @Override
    public void draw(Graphics g) {
        if (alive.get()) {
            g.drawImage(ImageUtil.homeImages[0], localX, localY, SIZE_X, SIZE_Y, null);
        } else {
            g.drawImage(ImageUtil.homeImages[1], localX, localY, SIZE_X, SIZE_Y, null);
        }
    }

    @Override
    public void init() {
        alive.set(true);
    }

    @Override
    public void destroy() {
        alive.set(false);
    }

    @Override
    public boolean alive() {
        return alive.get();
    }
}